package com.example.employ.controller;

import com.example.employ.common.convention.result.Result;
import com.example.employ.common.convention.result.Results;
import com.example.employ.dto.response.CompaniesListRespDTO;
import com.example.employ.dto.response.JobDetailRespDTO;
import com.example.employ.dto.response.JobListRespDTO;
import com.example.employ.dto.response.JobSearchRespDTO;
import com.example.employ.service.CompaniesService;
import com.example.employ.service.JobService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公司招聘管理
 */
@RestController
@RequiredArgsConstructor
public class CompaniesController {

    private final CompaniesService companiesService;
    private final JobService jobService;

    /**
     * 获取公司列表
     */
    @GetMapping("/api/recruit/v1/companies/list")
    public Result<List<CompaniesListRespDTO>> companiesList(){
        return Results.success(companiesService.companiesList());
    }

    /**
     * 查看公司招聘的职位(点击公司展现的列表)
     */
    @GetMapping("/api/recruit/v1/companies/job/list")
    public Result<List<JobListRespDTO>> jobList(@RequestParam(value = "companiesId", required = false) Long companiesId){
        return Results.success(jobService.jobList(companiesId));
    }

    /**
     * 职位详情
     */
    @GetMapping("/api/recruit/v1/companies/job/detail")
    public Result<JobDetailRespDTO> jobDetail(@RequestParam("companiesId") Long companiesId, @RequestParam("jobId") Long jobId){
        return Results.success(jobService.jobDetail(companiesId, jobId));
    }

    /**
     * 搜索职位(根据岗位名字进行模糊匹配查找)
     */
    @GetMapping("/api/recruit/v1/companies/job/search")
    public Result<List<JobSearchRespDTO>> search(@RequestParam(value = "name", required = false) String name){
        return Results.success(jobService.search(name));
    }
}
